load("//tools:build_defs.bzl", "accp_all_tests", "accp_tests", "bouncycastle_all_tests", "bouncycastle_tests", "conscrypt_all_tests", "conscrypt_tests", "spongycastle_all_tests", "spongycastle_tests")

testvectors = ["//testvectors_v1:all"]

# Java

java_library(
    name = "utils",
    srcs = [
        "java/com/google/security/wycheproof/EcUtil.java",
        "java/com/google/security/wycheproof/JsonUtil.java",
        "java/com/google/security/wycheproof/RandomUtil.java",
        "java/com/google/security/wycheproof/TestResult.java",
        "java/com/google/security/wycheproof/TestUtil.java",
        "java/com/google/security/wycheproof/TestVectors.java",
    ],
    deps = [
        "@com_google_code_gson_gson",
        "@com_google_guava",
        "@junit",
    ],
)

java_test(
    name = "TestUtilTest",
    size = "small",
    srcs = ["java/com/google/security/wycheproof/TestUtilTest.java"],
    test_class = "com.google.security.wycheproof.TestUtilTest",
    data = [
        ":wycheproof.java.security",
    ],
    jvm_flags = [
        "-Djava.security.properties=$(location //:wycheproof.java.security)",
    ],
    deps = [
        ":utils",
        "@com_google_guava",
        "@junit",
    ],
)

common_deps = [
    ":utils",
    "@com_google_code_gson_gson",
    "@junit",
]

test_srcs = glob([
    "java/**/WycheproofRunner.java",
    "java/**/testcases/*Test.java",
])

bouncycastle_all_tests(
    # This test takes a long time, because key generation for DSA and DH generate new parameters.
    size = "enormous",
    srcs = ["java/com/google/security/wycheproof/BouncyCastleAllTests.java"] + test_srcs,
    data = testvectors,
    test_class = "com.google.security.wycheproof.BouncyCastleAllTests",
    deps = common_deps,
)

java_test(
    name = "BouncyCastleAllTestsLocal",
    size = "enormous",
    srcs = ["java/com/google/security/wycheproof/BouncyCastleAllTests.java"] + test_srcs,
    data = testvectors,
    # this target requires specifing a shell variable, thus won't work with the wildcard target patterns.
    # with tags=["manual"] it'll be excluded from said patterns.
    tags = ["manual"],
    test_class = "com.google.security.wycheproof.BouncyCastleAllTests",
    deps = common_deps + ["@local//:bouncycastle_jar"],
)

bouncycastle_tests(
    size = "large",
    srcs = ["java/com/google/security/wycheproof/BouncyCastleTest.java"] + test_srcs,
    data = testvectors,
    test_class = "com.google.security.wycheproof.BouncyCastleTest",
    deps = common_deps,
)

java_test(
    name = "BouncyCastleTestLocal",
    size = "large",
    srcs = ["java/com/google/security/wycheproof/BouncyCastleTest.java"] + test_srcs,
    data = testvectors,
    # this target requires specifing a shell variable, thus won't work with the wildcard target patterns.
    # with tags=["manual"] it'll be excluded from said patterns.
    tags = ["manual"],
    test_class = "com.google.security.wycheproof.BouncyCastleTest",
    deps = common_deps + ["@local//:bouncycastle_jar"],
)

spongycastle_all_tests(
    # This test takes a long time, because key generation for DSA and DH generate new parameters.
    size = "enormous",
    srcs = ["java/com/google/security/wycheproof/SpongyCastleAllTests.java"] + test_srcs,
    data = testvectors,
    test_class = "com.google.security.wycheproof.SpongyCastleAllTests",
    deps = common_deps,
)

spongycastle_tests(
    size = "large",
    srcs = ["java/com/google/security/wycheproof/SpongyCastleTest.java"] + test_srcs,
    data = testvectors,
    test_class = "com.google.security.wycheproof.SpongyCastleTest",
    deps = common_deps,
)

conscrypt_tests(
    size = "large",
    srcs = ["java/com/google/security/wycheproof/ConscryptTest.java"] + test_srcs,
    data = testvectors,
    test_class = "com.google.security.wycheproof.ConscryptTest",
    deps = common_deps,
)

conscrypt_all_tests(
    size = "enormous",
    srcs = ["java/com/google/security/wycheproof/ConscryptAllTests.java"] + test_srcs,
    data = testvectors,
    test_class = "com.google.security.wycheproof.ConscryptAllTests",
    deps = common_deps,
)

accp_tests(
    size = "enormous",
    srcs = ["java/com/google/security/wycheproof/AccpTest.java"] + test_srcs,
    data = testvectors,
    test_class = "com.google.security.wycheproof.AccpTest",
    deps = common_deps,
)

java_test(
    name = "AccpTestLocal",
    size = "enormous",
    srcs = ["java/com/google/security/wycheproof/AccpTest.java"] + test_srcs,
    data = testvectors,
    # this target requires specifing a shell variable, thus won't work with the wildcard target patterns.
    # with tags=["manual"] it'll be excluded from said patterns.
    tags = ["manual"],
    test_class = "com.google.security.wycheproof.AccpTest",
    deps = common_deps + ["@local//:accp_jar"],
)

accp_all_tests(
    size = "enormous",
    srcs = ["java/com/google/security/wycheproof/AccpAllTests.java"] + test_srcs,
    data = testvectors,
    test_class = "com.google.security.wycheproof.AccpAllTests",
    deps = common_deps,
)

java_test(
    name = "AccpAllTestsLocal",
    size = "enormous",
    srcs = ["java/com/google/security/wycheproof/AccpAllTests.java"] + test_srcs,
    data = testvectors,
    # this target requires specifing a shell variable, thus won't work with the wildcard target patterns.
    # with tags=["manual"] it'll be excluded from said patterns.
    tags = ["manual"],
    test_class = "com.google.security.wycheproof.AccpAllTests",
    deps = common_deps + ["@local//:accp_jar"],
)

# OpenJDK tests
java_test(
    name = "OpenJDKTest",
    size = "large",
    srcs = ["java/com/google/security/wycheproof/OpenJDKTest.java"] + test_srcs,
    data = testvectors,
    test_class = "com.google.security.wycheproof.OpenJDKTest",
    deps = common_deps,
)

java_test(
    name = "OpenJDKAllTests",
    size = "large",
    srcs = ["java/com/google/security/wycheproof/OpenJDKAllTests.java"] + test_srcs,
    data = testvectors,
    test_class = "com.google.security.wycheproof.OpenJDKAllTests",
    deps = common_deps,
)

# Platform-independent tests
java_test(
    name = "ProviderIndependentTest",
    size = "small",
    srcs = ["java/com/google/security/wycheproof/ProviderIndependentTest.java"] + test_srcs,
    data = testvectors,
    deps = common_deps,
)
